﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Worktool.CODE_Chris.Forms.Update;

namespace Worktool.CODE_Chris.FileClasses
{
    public class GetXmlFile
    {
        public static Dictionary<string, string> dictSettings = new Dictionary<string, string>();

        public GetXmlFile()
        {
            init();
        }

        private void init()
        {
            //Ini-Datei einlesen
            setupDictionaryRessources();

            //dictSettings.Add("connectionString", "Server=" + dictSettings["server"] + ";Database=ASC_USER;User Id=ASC;Password=Asc0001!;");
            ////dictSettings.Add("connectionString", "Server=localhost;Database=ASC_USER;User Id=ASC;Password=Asc0001!;");

            //dictSettings.Add("connectionStringMASTER", "Server=" + dictSettings["server"] + ";Database=ASC_USER;User Id=ASC;Password=Asc0001!;");
            ////dictSettings.Add("connectionStringMASTER", "Server=localhost;Database=ASC_USER;User Id=ASC;Password=Asc0001!;");
        }


        private void setupDictionaryRessources()
        {
            try
            {
                //Zusätzliche Einträge in Dictionary schreiben (Absoluter Pfad des Programms, Name des Programms, Pfad + Name Ini- und Log-Datei)

                dictSettings.Add("apppath", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Remove(0, 6) + "\\");
                dictSettings.Add("appname", System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase));
                dictSettings.Add("inifile", dictSettings["apppath"] + dictSettings["appname"] + ".ini");
                dictSettings.Add("logfile", dictSettings["apppath"] + dictSettings["appname"] + ".log");

                //Serveradresse aus Xml-Datei lesen
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("asc.xml");
                XmlNodeList server = xmlDoc.GetElementsByTagName("serverName");
                dictSettings.Add("server", server[0].InnerText);

                server = xmlDoc.GetElementsByTagName("netzwerkordner");
                dictSettings.Add("netzwerkordner", server[0].InnerText);

                server = xmlDoc.GetElementsByTagName("asc_quantum");
                dictSettings.Add("asc_quantum", server[0].InnerText);

                server = xmlDoc.GetElementsByTagName("asc1_hyperion");
                dictSettings.Add("asc_hyperion", server[0].InnerText);

                server = xmlDoc.GetElementsByTagName("asc2_anthem");
                dictSettings.Add("asc_anthem", server[0].InnerText);

                //Dictionary in Main-Klasse übertragen
                Login.dictSettings = dictSettings;
                //SearchForUpdates.dictSettings = dictSettings;

            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

        }
    }
}
